package uplb.ics.cs190.e2d.io;

import java.io.InputStream;

import com.golden.gamedev.engine.BaseIO;
import com.golden.gamedev.util.ImageUtil;

import uplb.ics.cs190.e2d.graphics.AWTImage;
import uplb.ics.cs190.e2d.graphics.Image;
import uplb.ics.cs190.e2d.graphics.Transparency;

/**
 * The <code>StandardIO</code> provides the file input and output
 * functionalities for the J2SE platform.
 * 
 * This class uses GTGE's BaseIO engine for loading and saving
 * files, URLs or input streams.
 * 
 * @author Acer
 *
 */
public class StandardIO implements FileIO {

	protected BaseIO baseIO;
	
	public StandardIO(Class<?> base) {
		this.baseIO = new BaseIO(base);
	}
	
	@Override
	public Image getImage(String path) {
		AWTImage image = new AWTImage();
		image.setImage(ImageUtil.getImage(this.baseIO.getURL(path), Transparency.TRANSLUCENT));
		
		if(image.isEmpty()) {
			throw new RuntimeException();
		}
		
		return image;
	}
	
	@Override
	public File getFile(String path) {
		File file = null;
		
		return file;
	}
	
	@Override
	public InputStream getInputStream(String path) {
		InputStream stream = null;
		stream = baseIO.getStream(path);
		return stream;
	}

	public void setBase(Class<?> base) {
		this.baseIO.setBase(base);
	}
	
	public Class<?> getBase() {
		return this.baseIO.getBase();
	}
	
	public ClassLoader getLoader() {
		return this.baseIO.getLoader();
	}
}